<?php  
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Hello_controller extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->model('hello_model');
		$this->load->model('area_model');
	}


	function index()
	{

	}


	function to_create_hello()
	{
		$data['title']="Post New Hello";
		$data['id']="";
		$data['area']=$this->area_model->ChangeQueryResultToArray($this->area_model->getAll());
		$this->load->view('header',$data);
		$this->load->view('create_hello_form',$data);
		$this->load->view('footer',$data);
	}


	function create_hello()
	{
		// field name, error message, validation rules
		$this->load->library('form_validation');
		$this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[4]');
		$this->form_validation->set_rules('location', 'Location', 'trim|required|min_length[1]|max_length[32]');
		$this->form_validation->set_rules('time', 'Time', 'trim|required');
		$this->form_validation->set_rules('date', 'Date', 'trim|required');


		if($this->form_validation->run() == FALSE)
		{
			$this->to_create_hello();
		}
		else
		{
			if( $query = $this->hello_model->create() )
			{
				redirect('feed_controller/index');
			}
			else
			{
				$this->to_create_hello();
			}
		}
	}


}